﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace WpfApplication1.ViewModel
{
    public class MyViewModel : INotifyPropertyChanged
    {
        public MyViewModel(int rows, int cols)
        {
            BoxViewModels = new BoxViewModel[rows, cols];
            rIndex = cIndex = 0;
            rMax = rows;
            cMax = cols;
        }

        public void Increment()
        {
            for (int i = 0; i < 10; i++)
            {
                SomeText = string.Format(" Text {0}", i);
                Thread.Sleep(1000);
            }
        }

    public BoxViewModel[,] BoxViewModels;

        public event PropertyChangedEventHandler PropertyChanged;

        public string SomeText
        {
            get { return sText; }
            set
            {
                sText = value;
                PropertyChanged(this, new PropertyChangedEventArgs("SomeText"));
            }
        }

        private string sText;

        public void Switch()
        {
            if (full)
            {
                return;
            }

            BoxViewModels[rIndex, cIndex].Text = string.Format("{0}*{1}", rIndex, cIndex);
            cIndex++;
            if (cIndex == cMax)
            {
                cIndex = 0;
                rIndex++;
            }
            if (rIndex == rMax)
            {
                full = true;
            }

        }

        private bool full;
        private int rIndex, cIndex;
        private int rMax, cMax;
    }

    public class BoxViewModel : INotifyPropertyChanged
    {
        public string Text
        {
            get { return ss; }
            set
            {
                ss = value;
                PropertyChanged(this, new PropertyChangedEventArgs("Text"));
            }
        }

        private string ss;

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
